package com.chinatelecom.auth.mockmvc;

import com.chinatelecom.auth.AuthApplication;
import com.chinatelecom.auth.mockmvc.inter.AuthDetailInterface;
import com.chinatelecom.auth.mockmvc.inter.BuilderInterface;
import com.chinatelecom.auth.service.JedisService;
import org.junit.runner.RunWith;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;

/**
 * Created by liujinyao on 2017/7/27.
 */
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, classes = AuthApplication.class)
@RunWith(SpringRunner.class)
public class AuthDetail implements AuthDetailInterface {

    public final static String authKey = "systemcontroller:rightauthKey";
    public final static String username = "Tom";

    private JedisService jedisService;

    public AuthDetail(Builder builder){
        this.jedisService = builder.jedisService;
    }

    @Override
    public void run() {
        if(jedisService==null){
            return;
        }
        jedisService.put(authKey, username, 100000);
    }

    public static class Builder implements BuilderInterface<AuthDetail> {
        private JedisService jedisService;

        @Override
        public AuthDetail build() {
            return new AuthDetail(this);
        }

        public Builder jedisService(JedisService jedisService){
            this.jedisService = jedisService;
            return this;
        }
    }
}
